package lzupdater.utils;

//LZRosterUpdater, a java client to update LZRoster
//Copyright (C) 2008 Fraskor from Krasus (e-mail: fraskor@gmail.com)
//
//This file is part of LZRosterUpdater.
//
//LZRosterUpdater is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.

/**
 * 
 * @author Fraskor
 */
public class Pair<V1, V2> {
	private V1 value1;
	private V2 value2;

	public Pair(Pair<V1, V2> p) {
		this.value1 = p.value1;
		this.value2 = p.value2;
	}

	public Pair(V1 value1, V2 value2) {
		this.value1 = value1;
		this.value2 = value2;
	}

	public V1 getValue1() {
		return value1;
	}

	public void setValue1(V1 value1) {
		this.value1 = value1;
	}

	public V2 getValue2() {
		return value2;
	}

	public void setValue2(V2 value2) {
		this.value2 = value2;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null || !(obj instanceof Pair))
			return false;
		Pair<?, ?> tmp = (Pair<?, ?>) obj;

		return _equals(this.value1, tmp.value1)
				&& _equals(this.value2, tmp.value2);
	}

	public static <U, V> Pair<U, V> make(U v1, V v2) {
		return new Pair<U, V>(v1, v2);
	}

	private static <U> boolean _equals(U vRef, Object vTest) {
		return (vRef == null) ? vTest == null : vRef.equals(vTest);
	}

	@Override
	public int hashCode() {
		return value1.hashCode() << 17 + value2.hashCode();
	}

	@Override
	public String toString() {
		return String.format("<%s, %s>", value1, value2);
	}

}
